import sys
import unittest

sys.path.append('..')

class BoardTests(unittest.TestCase):

    def test_piece_placement(self):
        from sorto_board import SortoBoard

        # Check each board index 0-35 with each die roll
        for roll in range(1, 21):
            board = SortoBoard()
            res = board.convert_roll_to_index(roll)
            if roll == 1:
                self.assertEqual(res, (0, None))
            elif roll == 2:
                self.assertEqual(res, (1, None))
            elif roll == 3:
                self.assertEqual(res, (2, 3))
            elif roll == 4:
                self.assertEqual(res, (4, 5))
            elif roll == 5:
                self.assertEqual(res, (6, 7))
            elif roll == 6:
                self.assertEqual(res, (8, 9))
            elif roll == 7:
                self.assertEqual(res, (10, 11))
            elif roll == 8:
                self.assertEqual(res, (12, 13))
            elif roll == 9:
                self.assertEqual(res, (14, 15))
            elif roll == 10:
                self.assertEqual(res, (16, 17))
            elif roll == 11:
                self.assertEqual(res, (18, 19))
            elif roll == 12:
                self.assertEqual(res, (20, 21))
            elif roll == 13:
                self.assertEqual(res, (22, 23))
            elif roll == 14:
                self.assertEqual(res, (24, 25))
            elif roll == 15:
                self.assertEqual(res, (26, 27))
            elif roll == 16:
                self.assertEqual(res, (28, 29))
            elif roll == 17:
                self.assertEqual(res, (30, 31))
            elif roll == 18:
                self.assertEqual(res, (32, 33))
            elif roll == 19:
                self.assertEqual(res, (34, None))
            elif roll == 20:
                self.assertEqual(res, (35, None))
                pass                
            pass
        return

    def test_legal_placement(self):
        from sorto_board import SortoBoard

        # Check each board index 0-35 with each die roll
        counter = 1
        for roll in range(1, 21):
            board = SortoBoard()
            res = board.legal_places_for_roll_and_counter(roll, counter)
            if roll == 1:
                self.assertEqual(res, [0,])
            elif roll == 2:
                self.assertEqual(res, [1,])
            elif roll == 3:
                self.assertEqual(res, [2, 3])
            elif roll == 4:
                self.assertEqual(res, [4, 5])
            elif roll == 5:
                self.assertEqual(res, [6, 7])
            elif roll == 6:
                self.assertEqual(res, [8, 9])
            elif roll == 7:
                self.assertEqual(res, [10, 11])
            elif roll == 8:
                self.assertEqual(res, [12, 13])
            elif roll == 9:
                self.assertEqual(res, [14, 15])
            elif roll == 10:
                self.assertEqual(res, [16, 17])
            elif roll == 11:
                self.assertEqual(res, [18, 19])
            elif roll == 12:
                self.assertEqual(res, [20, 21])
            elif roll == 13:
                self.assertEqual(res, [22, 23])
            elif roll == 14:
                self.assertEqual(res, [24, 25])
            elif roll == 15:
                self.assertEqual(res, [26, 27])
            elif roll == 16:
                self.assertEqual(res, [28, 29])
            elif roll == 17:
                self.assertEqual(res, [30, 31])
            elif roll == 18:
                self.assertEqual(res, [32, 33])
            elif roll == 19:
                self.assertEqual(res, [34,])
            elif roll == 20:
                self.assertEqual(res, [35,])
                pass                
            pass
        return

    pass # End of class BoardTests

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(BoardTests)
    unittest.TextTestRunner(verbosity=2).run(suite)
    sys.exit(0)
